from flask import Flask, request, jsonify, Blueprint
from models import db, Course, Class, Student, Enrollment, Grade

api = Blueprint('api', __name__)

# 学生管理
@api.route('/students', methods=['GET'])
def get_students():
    students = Student.query.all()
    return jsonify([{'student_id': s.student_id, 'student_name': s.student_name} for s in students])

@api.route('/students', methods=['POST'])
def create_student():
    data = request.json
    new_student = Student(student_name=data['student_name'])
    db.session.add(new_student)
    db.session.commit()
    return jsonify({'message': 'Student created'})